#!/usr/bin/env python3
"""
简单测试AI对话功能修复效果
"""

import requests
import json

def test_ai_chat_simple():
    """简单测试AI对话接口"""
    print("=== 简单测试AI对话功能修复效果 ===")
    
    # 测试数据
    test_data = {
        "prompt": "请介绍一下硅材料的基本特性",
        "material_data": {
            "material_id": "mp-149",
            "formula_pretty": "Si",
            "symmetry": {
                "crystal_system": "cubic",
                "symbol": "Fd-3m"
            },
            "band_gap": 1.12,
            "density": 2.33,
            "volume": 20.0
        },
        "temperature": 0.7,
        "max_tokens": 100
    }
    
    try:
        # 使用requests库进行简单测试
        print("测试AI对话接口...")
        response = requests.post(
            "http://localhost:8001/ai/chat/simple",
            json=test_data,
            headers={"Content-Type": "application/json"},
            timeout=30
        )
        
        if response.status_code == 200:
            print("[SUCCESS] 接口连接成功")
            result = response.json()
            print(f"[SUCCESS] 响应数据: {json.dumps(result, ensure_ascii=False, indent=2)}")
            
            # 检查响应格式
            if "response" in result:
                content = result["response"]
                if content and len(content) > 0:
                    print("[SUCCESS] AI对话功能修复成功！")
                    print(f"[SUCCESS] 响应内容: {content[:200]}...")
                    return True
                else:
                    print("[ERROR] 响应内容为空")
            else:
                print("[ERROR] 响应格式不正确")
        else:
            print(f"[ERROR] 接口请求失败: {response.status_code}")
            print(f"响应内容: {response.text}")
            
    except Exception as e:
        print(f"[ERROR] 测试过程中出错: {e}")
    
    return False

if __name__ == "__main__":
    success = test_ai_chat_simple()
    if success:
        print("\n[SUCCESS] AI对话功能修复验证完成！")
    else:
        print("\n[ERROR] AI对话功能修复验证失败！")